<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="utf-8">
		<meta name="referrer" content="no-referrer" />
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
		<title>发布商品</title>
		<link rel="icon" href="favicon.ico" type="image/ico">
		<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
		<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
		<meta name="author" content="yinqi">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/materialdesignicons.min.css" rel="stylesheet">
	<!--	<link href="css/bese.css" rel="stylesheet">-->
		<link rel="stylesheet" href="js/dropzone/min/basic.min.css" />
		<link rel="stylesheet" href="js/dropzone/min/dropzone.min.css" />
		<link rel="stylesheet" href="js/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
		<!--对话框-->
		<link rel="stylesheet" href="js/jconfirm/jquery-confirm.min.css">
		<link href="css/sort.css" rel="stylesheet">
<!--		连续5个上传图片-->
		<link rel="stylesheet" href="js/goodUploadImg/upload.css">
		<link rel="stylesheet" href="js/goodUploadImg/uploadImg.css">
	</head>
	<body>

		<div class="container-fluid p-t-15">
			<div class="row">
				<div class="col-md-12">
					<div class="card">
						<div class="card-header">
							<h4>发布商品</h4>
						</div>
						<div class="card-body">
							<form class="form-horizontal" onsubmit="return false;">
								<div class="form-group">

									<div class="contains">
										<!--商品分类-->
										<div class="wareSort clearfix">
											<ul id="sort1" style="height: 250px;overflow: scroll;overflow-x:hidden"></ul>
											<ul id="sort2" style="display: none;height: 250px;overflow: scroll;overflow-x:hidden"></ul>
											<ul id="sort3" style="display: none;height: 250px;overflow: scroll;overflow-x:hidden"></ul>
										</div>
										<div class="selectedSort">
											<input  type="hidden"  id="productTypeName" >
											<b>您当前选择的商品类别是：</b>
											<i id="selectedSort"></i>
										</div>
									</div>

								</div>

								<h5 class="text-one">商品信息规格与库存</h5>
								<!-- 商品标题 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="goods_name"><span class="text-red">*</span>商品标题</label>
									<div class="col-xs-8">
										<input class="form-control" type="text" id="productName" name="productName" placeholder="请输入您的商品标题">
										<div class="help-block">商品标题名称长度至少3个字符，最长50个汉字。根据消费者习惯，建议标题的设置尽可能全面概括。</div>
									</div>
								</div>

								<!-- 商品规格 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="goods_name">商品规格</label>
									<div class="col-xs-8">
										<div class="help-block">最多添加两个商品规格(不需要可以不选)</div>
<!--										规格一-->
										<div>
											<div class="row bg">
												<div class="col-xs-9">
													<select class="form-control gg-select" id="select-1" name="sku_one_name" size="1">
														<option value="0">请选择规格一</option>

													</select>
												</div>
											</div>

											<div class="row bg-fb div-g-1">
												<div class="col-xs-4 m-tb">
													<div class="input-group ">
														<input type="text" class="form-control i-gg i-gg-1" flag="1"/>
													</div>
												</div>
											</div>
											<button class="btn btn-label btn-default m-tb attr-b" type="1">
												<label><i class="mdi mdi-loupe"></i></label>添加属性
											</button>
										</div>
<!--										规格一结束-->
										<div>
											<div class="row bg">
												<div class="col-xs-9">
													<select class="form-control gg-select" id="select-2" name="sku_two_name" size="1">
														<option value="0">请选择规格二</option>

													</select>
												</div>

											</div>

											<div class="row bg-fb div-g-2">

												<div class="col-xs-4 m-tb">
													<div class="input-group">
														<input type="text" class="form-control i-gg i-gg-2" flag="2"/>
													</div>
												</div>

											</div>
											<button class="btn btn-label btn-default m-tb attr-b" type="2">
												<label><i class="mdi mdi-loupe"></i></label>添加属性
											</button>
										</div>
<!--										规格二-->
									</div>
								</div>
								<!-- 价格及库存 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="goods_name">价格及库存</label>
									<div class="col-xs-8 bg-fb">
										<div class="row div_hide" style="display: none">
											<div class="help-block col-xs-9">
												批量设置<span class="text-two">在下方栏中选择内容进行批量填充</span>
											</div>
											<div class="col-xs-3">
												<button class="btn btn-info fr" id="set_bun">立即设置</button>
											</div>
										</div>

										<div class="row div_hide" style="display: none">
											<div class="col-xs-2">
												<select class="form-control" id="select-sku-1"  size="1">
													<option value="全部">全部</option>
												</select>
											</div>
											<div class="col-xs-2">
												<select class="form-control" id="select-sku-2" size="1">
													<option value="全部">全部</option>
												</select>
											</div>

											<div class="col-xs-3">
												<div class="input-group">
													<span class="input-group-addon">库存</span>
													<input type="text" class="form-control" id="input_kc"/>
												</div>
											</div>
											<div class="col-xs-3">
												<div class="input-group">
													<span class="input-group-addon">¥</span>
													<input type="text" class="form-control" id="input_fnj"/>
												</div>
											</div>
										</div>

										<table class="table table-bordered">
											<thead id="gg-thead">
												<!--<tr>
													<th id="th-gg-1">规格一</th>
													<th id="th-gg-2">规格二</th>
													<th><span class="text-red">*</span>库存</th>
													<th><span class="text-red" >*</span>烽鸟价（元）</th>
													<th><span class="text-red">*</span>积分赠送</th>
													<th><span class="text-red">*</span>代金卷赠送</th>
													<th><span class="text-red">*</span>预览图</th>
												</tr>-->
											</thead>
											<tbody id="gg-tbody">
												<!--<tr>
													<td>12</td>
													<td>12</td>
													<td>
														<input class="pdd-form-input" type="text" value="">
													</td>
													<td>
														<input class="pdd-form-input" type="text" value="">
													</td>
													<td>
														<input class="pdd-form-input" type="text" value="">
													</td>
													<td>
														<input class="pdd-form-input" type="text" value="">
													</td>
													<td>
														<ul class="list-inline clearfix lyear-uploads-pic">
															&lt;!&ndash; <li>
																<img src="images/gallery/17.jpg" alt="图片三">
															 </li> &ndash;&gt;
															<li class="example-p-id">
																<a class="pic-add pic-add-none" id="add-pic-btn" href="#!" title="点击上传"></a>
															</li>
														</ul>
													</td>
												</tr>-->
											</tbody>
										</table>

										<table class="table table-bordered div_hide" style="display: none" id="gg_table">
											<thead>
												<tr>
													<th>总库存</th>
													<th>烽鸟价（元）</th>
													<th>积分赠送</th>
													<th>代金券赠送</th>
													<th>需要金券</th>
													<th>商品货号</th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td id="td_kc"></td>
													<td id="td_fnj"></td>
													<td id="td_jfzs"></td>
													<td id="td_jqzs"></td>
													<td id="td_xyjq"></td>
													<td>
														<input class="pdd-form-input" id="hide_sphh" type="text" value="">
													</td>
												</tr>
											</tbody>
										</table>
<!--										没有填规格，默认显示的-->
										<table class="table table-bordered div_show">
											<thead>
											<tr>
                                                <th><span class="text-red">*</span>库存</th>
                                                <th><span class="text-red" >*</span>烽鸟价（元）</th>
                                                <th><span class="text-red">*</span>积分赠送</th>
                                                <th><span class="text-red">*</span>代金卷赠送</th>
                                                <th><span class="text-red">*</span>需要金券</th>
                                                <th><span class="text-red">*</span>商品货号</th>
                                            </tr>
											</thead>
											<tbody>
											<tr>
                                                <td>
                                                    <input class="pdd-form-input" id="show_kc" type="text" value="">
                                                </td>
                                                <td>
                                                    <input class="pdd-form-input" id="show_fnj" type="text" value="">
                                                </td>
                                                <td>
                                                    <input class="pdd-form-input" id="show_jfzs" type="text" value="" readonly="readonly">
                                                </td>
                                                <td>
                                                    <input class="pdd-form-input" id="show_jqzs" type="text" value="">
                                                </td>
												<td>
													<input class="pdd-form-input" id="show_xyjq" type="text" value="">
												</td>
												<td>
													<input class="pdd-form-input" id="show_sphh" type="text" value="">
												</td>
                                            </tr>
											</tbody>
										</table>
									</div>
								</div>

								<!-- 市场价 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="marketPrice">市场价</label>
									<div class="col-xs-4">
										<input class="form-control" type="text" id="marketPrice" placeholder="请输入您的商品的市场价">
									</div>
									<div class="col-xs-4 line-h40">元</div>
								</div>

								<!-- 结算比例 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="settleCurrency">结算比例</label>
									<div class="col-xs-4">
										<input class="form-control" type="text" id="settleCurrency" placeholder="请输入您的商品的结算比例">
										<div class="help-block">根据销售价与市场价比例自动生成，不需要编辑。</div>
									</div>
									<div class="col-xs-4 line-h40">% <span class="text-red">成为联盟商家/联盟企业可修改比例</span></div>
								</div>

								<!-- 赠与比例 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="favourCurrentcy">赠与比例</label>
									<div class="col-xs-4">
										<input class="form-control" type="text" id="favourCurrentcy"  placeholder="请输入您的商品的赠与比例">
										<div class="help-block">帮助商家继续回流客户，根据结算比例自动生成，不需要编辑，赠与消费者消费金额100%购物积分，同时商家可获得消费金额16%购物积分，可兑换成16%的库存广告积分</div>
									</div>
									<div class="col-xs-4 line-h40"> % <span class="text-red">成为联盟商家/联盟企业可修改比例</span></div>
								</div>

								<h5 class="text-one">图文描述</h5>

								<!-- 商品图片 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0">商品图片</label>
									<div class="col-xs-8">
										<div class="help-block">
											商品主图大小不能超过3MB; 700*700 以上图片。支持jpg、jpeg、gif、png格式上传或从图片空间中选择
										</div>

										<div class="form-controls">
											<div class="upload-content">
												<div class="content-img">
													<ul class="content-img-list"></ul>
													<div class="file">
														<i class="gcl gcladd"></i>
														<input type="file" name="file" accept="image/*" id="upload" multiple>
													</div>
												</div>
												<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
													<div class="modal-dialog modal-lg" role="document">
														<div class="img-up-content">
														</div>
													</div>
												</div>
											</div>
											<!--<ul class="list-inline clearfix lyear-uploads-pic">
												<li class="col-xs-3 col-sm-3 col-md-2">
													&lt;!&ndash;<figure>
													  <img src="images/gallery/16.jpg" alt="图片二">
													  <figcaption>
													    <a class="btn btn-round btn-square btn-danger" href="#!"><i class="mdi mdi-delete"></i></a>
													  </figcaption>
													</figure>&ndash;&gt;
													<input type="hidden" name="logo" id="logo">
													<div id="example-dropzone"  class="dropzone"></div>
												</li>
												<li class="col-xs-3 col-sm-3 col-md-2">
													<a class="pic-add" id="add-pic-btn" href="#!" title="点击上传"></a>
												</li>
												<li class="col-xs-3 col-sm-3 col-md-2">
													<a class="pic-add" id="add-pic-btn" href="#!" title="点击上传"></a>
												</li>
												<li class="col-xs-3 col-sm-3 col-md-2">
													<a class="pic-add" id="add-pic-btn" href="#!" title="点击上传"></a>
												</li>
												<li class="col-xs-3 col-sm-3 col-md-2">
													<a class="pic-add" id="add-pic-btn" href="#!" title="点击上传"></a>
												</li>
											</ul>-->
										</div>
									</div>
								</div>

								<!-- 主体视频 -->
								<div class="form-group">
									<label class="col-xs-3 control-label font-0">主图视频比例</label>
									<div class="col-xs-8">
										<div class="help-block">
											<label class="lyear-radio radio-inline radio-primary">
												<input type="radio" name="videoType" value="0"><span>1:1或16:9</span>
											</label>
											<label class="lyear-radio radio-inline radio-primary">
												<input type="radio" name="videoType" value="1"><span>3：4</span>
											</label>
										</div>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0">主图视频</label>
									<div class="col-xs-8">
										<ul class="col-xs-4 list-inline clearfix lyear-uploads-pic">
											<li>
<!--												<div>-->
													<input type="hidden" id="videoInp">
<!--													<form id="videoFrom" action="/remote/upload/video" method="post"-->
<!--														  enctype="multipart/form-data">-->
														<div class="form-group col-md-6">
														<span class="btn btn-info video-button">
															  <i class="mdi mdi-plus"></i>
															  <span id="videoValue">添加视频</span>
														   </span>

															<span class="btn btn-danger">
															  <i class="mdi mdi-plus"></i>
															  <span id="deleteVideo">删除视频</span>
														   </span>
															<input type="file" accept="video/*" name="file" id="videoFile"
																   style="display: none">
														</div>
<!--													</form>-->
													<div>
														<video id="video_div" style="width:200px;height: 100px;display: none" src=""  controls="controls"></video>
													</div>
<!--												</div>-->
											</li>
										</ul>
										<ul class="col-xs-8 text-gray">
											<ol>
												1.尺寸：此次可使用1:1或16:9比例视频
											</ol>
											<ol>
												2.时长：15秒-60秒，建议控制在30秒内，节奏明快有助成交
											</ol>
											<ol>
												3.内容：突出表现1-2个商品核心卖点，画质清晰，真人演示等效果更好
											</ol>
										</ul>
									</div>
								</div>

								<div class="form-group">
									<label class="col-xs-3 control-label font-0">文本编辑</label>
									<div class="col-xs-8">
<!--										style="border:1px solid; height: 300px;"-->
										<textarea id="editor" name="details"></textarea>
									</div>
								</div>

								<h5 class="text-one">物流信息</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0">提取方式</label>
									<div class="col-xs-8">
										<div class="help-block u-f-ac">
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" checked=""><span class="m-l-10">使用物流配送</span>
											</label>
											<span class="m-l-15">为了提升消费者购物体验，烽鸟易购要求全网商品设置运费模板</span>
										</div>
										<div class="row bg-fb u-f-ac p-10">
											<div class="col-xs-2 col-md-3">
												运费模板
											</div>
											<div class="col-xs-3 col-md-6">
												<select class="form-control" id="example-select" name="example-select" size="1">
													<option value="0">规格1</option>
													<option value="1">尺寸</option>
													<option value="2">型号</option>
													<option value="3">款式</option>
												</select>
											</div>
											<div class="col-xs-4 col-md-3 u-f-ac">
												<button class="btn btn-danger m-r-10" style="float: right;" type="button">新建运费模板</button>
												<button class="btn btn-danger" style="float: right;" type="button">刷新模板数据</button>
											</div>
										</div>
									</div>
								</div>

								<h5 class="text-one">另添加上架区域</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="goods_name"></label>
									<div class="col-xs-9">
										<div class="help-block u-f-ac">
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="2"><span class="m-l-10">烽鸟驿站</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="3"><span class="m-l-10">烽鸟同城</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="4"><span class="m-l-10">扶贫助农</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="5"><span class="m-l-10">全国好货</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="6"><span class="m-l-10">9.9包邮</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="7"><span class="m-l-10">新人专区</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="8"><span class="m-l-10">代金券专区</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="9"><span class="m-l-10">今日上新</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" name="plateId" value="10"><span class="m-l-10">限时秒杀</span>
											</label>
										</div>
									</div>
								</div>

								<h5 class="text-one">商店分类</h5>
								<div class="form-group" id="b_show_div">
									<label class="col-xs-3 control-label font-0"  for="b_type"></label>
									<div class="col-xs-9">
										<select class="form-control" id="b_type" name="b_type">
										</select>
									</div>
								</div>

								<div class="form-group" id="b_hide_div">
									<label class="col-xs-3 control-label font-0"  for="b_type"></label>
									<div class="col-xs-9">
										<span>还没店铺分类，请去创建</span>
									</div>
								</div>

								<h5 class="text-one">商品排序</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0"  for="sort"></label>
									<div class="col-xs-9">
										<input id="sort" name="sort" type="text" value="0">
									</div>
								</div>

								<h5 class="text-one">秒杀限购数量(只有驿站秒杀商品才需要填写，其他板块都默认)</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0"  for="buyLimit"></label>
									<div class="col-xs-9">
										<input id="buyLimit" name="buyLimit" type="text" value="0">
									</div>
								</div>

								<h5 class="text-one">分享比例</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0"  for="share"></label>
									<div class="col-xs-9">
										<input type="text" name="share" id="share"  value="0" oninput="value=value.replace(/[^\d]/g,'')">%
									</div>
								</div>

								<h5 class="text-one">佣金比例</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0"  for="reward"></label>
									<div class="col-xs-9">
										<input type="text" name="reward" id="reward"  value="10" oninput="value=value.replace(/[^\d]/g,'')">%
									</div>
								</div>

								<h5 class="text-one">售后服务</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="goods_name"></label>
									<div class="col-xs-9">
										<div class="help-block u-f-ac">
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox"><span class="m-l-10">提供发票</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox"><span class="m-l-10">立即上架</span>
											</label>
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox"><span class="m-l-10">放入仓库</span>
											</label>
										</div>
									</div>
								</div>

								<h5 class="text-one">是否推荐</h5>
								<div class="form-group">
									<label class="col-xs-3 control-label font-0" for="goods_name"></label>
									<div class="col-xs-9">
										<div class="help-block u-f-ac">
											<label class="lyear-checkbox checkbox-primary text-none">
												<input type="checkbox" id="isRecommend"><span class="m-l-10">是</span>
											</label>
										</div>
									</div>
								</div>

								<div class="u-f-ajc p-15">
									<button class="btn btn-danger" id="sub_btn" style="float: right;" type="button">提交商品信息</button>
								</div>

							</form>
						</div>
					</div>
				</div>
			</div>
		</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/sort.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<!-- jquery-form表单提交插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
<!--对话框-->
<script src="js/jconfirm/jquery-confirm.min.js"></script>

<script type="text/javascript" src="js/main.min.js"></script>
<script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.drop.js"></script>
<!-- ztree树插件 -->
<script type="text/javascript" src="js/ztree/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.ztree.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!--连续5个上传图片-->
<script src="js/goodUploadImg/uploadImg.js"></script>
<!-- edu富文本插件 -->
<script type="text/javascript" charset="utf-8" src="js/plugin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="js/plugin/ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="js/plugin/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8" src="js/zero2oneMath.js"></script>

<script type="text/javascript">

	var ue = UE.getEditor('editor');
	//复写UEDITOR的getActionUrl 方法,定义自己的Action
	//上传图片
	UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
	UE.Editor.prototype.getActionUrl = function(action) {
		if (action == 'uploadimage' ) {
			return '/ueditorUploadFile';
		} else {
			return this._bkGetActionUrl.call(this, action);
		}
	};

	//查询该店铺的分类
	$.post("/remote/BusinCate/getByBusinessId",{businessId:0},function (res) {
		if (res.success){
			$("#b_type").empty();
			var tempArr = res.data;
			if (tempArr==null||tempArr.length===0){
				$("#b_hide_div").show();
				$("#b_show_div").hide();
				return;
			}else {
				$("#b_hide_div").hide();
				$("#b_show_div").show();
			}
			var str='<option value="0">请选择商店分类</option>';
			$.each(tempArr,function (index,item) {
				str+='<option value="'+item.id+'">'+item.name+'</option>'
			});
			$("#b_type").append(str);
		}
	});

	//查询所有规格
	$.post("/remote/spec/specList",{},function (res) {
		var arr=res.data;
		var str='';
		$.each(arr,function (index,item) {
			str+='<option value="'+item.id+'">'+item.specName+'</option>'
		});
		$("#select-1").append(str);
		$("#select-2").append(str);
	});
	//全局函数保存两个sku属性数组
	var skuOne=[];
	var skuTwo=[];
	//判断输入框的值是否有改变，，改变了才添加到数组
	var tempValue;
	//属性框获取焦点函数
	function attrFocus(){
		tempValue=this.value.replace(/\s+/g,"");

	}
	//绑定属性框获取焦点函数
	$(".i-gg").on("focus", attrFocus);

	function min(flag) {
	    var arr;
        var that;
	    if (flag===1){
            arr = $(".fnj");
            that=$("#td_fnj")
        } else if (flag===2){
            arr = $(".jfzs");
            that=$("#td_jfzs")
        }else if (flag===3){
            arr = $(".jqzs");
            that=$("#td_jqzs")
        }else if (flag===4){
			arr = $(".xyjq");
			that=$("#td_xyjq")
		}
        var min=arr[0].value-0;
        $.each(arr,function (index,item) {
            if ((item.value-0)<min) min=(item.value-0)
        });
        that.text(min);

	}

	function total() {
		var kcArr = $(".kc");
		var totalKc=0;
		$.each(kcArr,function (index,item) {
			totalKc+=(item.value-0)
		});
		$("#td_kc").text(totalKc);
	}
	//设置按钮点击事件
	function setting() {
		var kc = $("#input_kc").val().trim();
		if (kc==null||kc===''){
			return $.messager.alert("验证提示", "库存不能为空");
		}
		var fnj = $("#input_fnj").val().trim();
		if (fnj==null||fnj===''){
			return $.messager.alert("验证提示", "价格不能为空");
		}
		var sku_one = $("#select-sku-1").find("option:selected").val();
		var sku_two = $("#select-sku-2").find("option:selected").val();
		if (sku_one==='全部'){
			if (sku_two==='全部'){
				$("input.kc").val(kc);
				$("input.fnj").val(fnj)
			} else {
				$("input.kc.kc-g2-"+sku_two).val(kc);
				$("input.fnj.fnj-g2-"+sku_two).val(fnj)
			}
		}else {
			if (sku_two==='全部'){
				$("input.kc.kc-g1-"+sku_one).val(kc);
				$("input.fnj.fnj-g1-"+sku_one).val(fnj)
			} else {
				$("input.kc.kc-g1-"+sku_one+".kc-g2-"+sku_two).val(kc);
				$("input.fnj.fnj-g1-"+sku_one+".fnj-g2-"+sku_two).val(fnj);
			}
		}
		//设置最下面的值
		total();
		min(1);
        $("#td_jfzs").text('');
        $("#td_jqzs").text('');
        $("#td_xyjq").text('');
	}
	$("#set_bun").on("click", setting);

	//规格表里面的kc input失去焦点函数
	function kc_blur() {
		total()
	}
	//规格表烽鸟价 input失去焦点事件
	function fn_blur() {
	    if ($(this).hasClass("fnj")){
            min(1)
        }else if ($(this).hasClass("jqzs")) {
            min(3)
        }else if ($(this).hasClass("xyjq")) {
			min(4)
		}
	}
	$(".kc").on("blur", kc_blur);
	$(".fnj").on("blur", fn_blur);
	$(".jqzs").on("blur", fn_blur);
	$(".xyjq").on("blur", fn_blur);

	//公共方法
	function common(flag,arr) {
		//把规格二框的值放到表头
		var value = $("#select-"+flag).find("option:selected").text();
		var str='<tr>\n' +
				'<th id="th-gg-'+flag+'">'+value+'</th>\n' +
				'<th><span class="text-red">*</span>库存</th>\n' +
				'<th><span class="text-red" >*</span>烽鸟价（元）</th>\n' +
				'<th><span class="text-red">*</span>积分赠送</th>\n' +
				'<th><span class="text-red">*</span>代金卷赠送</th>\n' +
				'<th><span class="text-red">*</span>需要金券</th>\n' +
				'<th><span class="text-red">*</span>预览图</th>\n' +
				'</tr>';
		$("#gg-thead").append(str);
		str='';
		//遍历数组拿出数组
		for (var i = 0; i < arr.length; i++) {
			str+='<tr>\n' +
					'<td>'+arr[i]+'</td>\n' +
					'<td>\n' +
					'<input class="pdd-form-input kc kc-g'+flag+"-"+arr[i]+'"type="text" value="">\n' +
					'</td>\n' +
					'<td>\n' +
					'<input class="pdd-form-input fnj fnj-g'+flag+"-"+arr[i]+'"type="text" value="">\n' +
					'</td>\n' +
					'<td>\n' +
					'<input class="pdd-form-input jfzs" type="text" value="" readonly="readonly">\n' +
					'</td>\n' +
					'<td>\n' +
					'<input class="pdd-form-input jqzs" type="text" value="">\n' +
					'</td>\n' +
					'<td>\n' +
					'<input class="pdd-form-input xyjq" type="text" value="">\n' +
					'</td>\n' +
					'<td>\n' +
					'<input type="hidden" name="logo" id="up-'+arr[i]+'">\n'+
					'<div id="dropzone'+arr[i]+'"  class="dropzone"></div>\n'+
					'</td>\n' +
					'</td>\n' +
					'</tr>'

		}
		$("#gg-tbody").append(str);
		$(".kc").unbind("blur").on("blur", kc_blur);
		$(".fnj").unbind("blur").on("blur", fn_blur);
		$(".jqzs").unbind("blur").on("blur", fn_blur);
		$(".xyjq").unbind("blur").on("blur", fn_blur);
		//上传图片
		for (var j = 0; j < arr.length; j++) {
				zero2one.drop1("dropzone"+arr[j],"up-"+arr[j],"+");
			}
	}

	//两个数组都有值调用的方法
	function descartes() {
		var value_one = $("#select-1").find("option:selected").text();
		var value_two= $("#select-2").find("option:selected").text();
		var str='<tr>\n' +
				'<th id="th-gg-1">'+value_one+'</th>\n' +
				'<th id="th-gg-2">'+value_two+'</th>\n' +
				'<th><span class="text-red">*</span>库存</th>\n' +
				'<th><span class="text-red" >*</span>烽鸟价（元）</th>\n' +
				'<th><span class="text-red">*</span>积分赠送</th>\n' +
				'<th><span class="text-red">*</span>代金卷赠送</th>\n' +
				'<th><span class="text-red">*</span>需要金券</th>\n' +
				'<th><span class="text-red">*</span>预览图</th>\n' +
				'</tr>';
		$("#gg-thead").append(str);
		str='';
		for (var i = 0; i < skuOne.length; i++) {
			for (var j = 0; j < skuTwo.length; j++) {
				str+='<tr>\n' +
						'<td>'+skuOne[i]+'</td>\n' +
						'<td>'+skuTwo[j]+'</td>\n' +
						'<td>\n' +
						'<input class="pdd-form-input kc kc-g1-'+skuOne[i]+' kc-g2-'+skuTwo[j]+'"type="text" value="">\n' +
						'</td>\n' +
						'<td>\n' +
						'<input class="pdd-form-input fnj fnj-g1-'+skuOne[i]+' fnj-g2-'+skuTwo[j]+'"type="text" value="">\n' +
						'</td>\n' +
						'<td>\n' +
						'<input class="pdd-form-input jfzs" type="text" value="" readonly="readonly">\n' +
						'</td>\n' +
						'<td>\n' +
						'<input class="pdd-form-input jqzs" type="text" value="">\n' +
						'</td>\n' +
						'<td>\n' +
						'<input class="pdd-form-input xyjq" type="text" value="">\n' +
						'</td>\n' +
						'<td>\n' +
						'<input type="hidden" name="logo" id="up-'+skuOne[i]+'-'+skuTwo[j]+'">\n' +
						'<div id="dropzone'+skuOne[i]+'-'+skuTwo[j]+'"  class="dropzone"></div>\n'+
						'</td>\n' +
						'</tr>'
			}
		}
		$("#gg-tbody").append(str);
		$(".kc").unbind("blur").on("blur", kc_blur);
        $(".fnj").unbind("blur").on("blur", fn_blur);
        $(".jqzs").unbind("blur").on("blur", fn_blur);
        $(".xyjq").unbind("blur").on("blur", fn_blur);
		for (var k = 0; k < skuOne.length; k++) {
			for (var l = 0; l < skuTwo.length; l++) {
				zero2one.drop1("dropzone"+skuOne[k]+'-'+skuTwo[l],'up-'+skuOne[k]+'-'+skuTwo[l],"+");
			}
		}
	}

	//属性框失去焦点函数
	function attrBlur(){
		var flag = $(this).attr('flag');
		var value=$(this).val().replace(/\s+/g,"");
		if (tempValue===value){
			if (value==null||value===''||value===""){
				$(this).parent().parent().remove();
			}
			return
		}
		if (value==null||value===''||value===""){
			$(this).parent().parent().remove();
		}
		var arr = $('.i-gg'+'-'+flag);
		var temp=[];
		for (var i = 0; i < arr.length; i++) {
			var trim = arr[i].value.replace(/\s+/g,"");
			if (trim.length===0)continue;
			if (temp.indexOf(trim)===-1){
				temp.push(trim)
			}
		}
		if (flag=='1'){
			skuOne=temp
		} else {
			skuTwo=temp
		}
		var str='<option value="全部">全部</option>';
		for (var i = 0; i < temp.length; i++) {
			str+='<option value="'+temp[i]+'">'+temp[i]+'</option>'
		}
		$("#select-sku-"+flag).empty();
		$("#select-sku-"+flag).append(str);

		//价格与库存表的操作
		//把两个数组的值，笛卡尔积
		$("#gg-thead").empty();
		$("#gg-tbody").empty();
		if (skuOne.length===0){
			if (skuTwo.length===0){
				$('.div_hide').css("display","none");//不展示div
				$('.div_show').css("display","block");//显示div
				$("#set_bun").unbind("click").on("click", setting);
			} else {
				common("2", skuTwo);
				$('.div_hide').css("display", "block");//显示div
				$('.div_show').css("display","none");//不显示div
				$("#set_bun").unbind("click").on("click", setting);
				}
		}else{
			if (skuTwo.length===0){
				common("1",skuOne)
			} else {
				descartes()
			}
			$('.div_hide').css("display","block");//显示div
			$('.div_show').css("display","none");//不显示div
			$("#set_bun").unbind("click").on("click", setting);
		}

	}
	//绑定属性框失去焦点函数
	$(".i-gg").on("blur", attrBlur);


	//全局变量
	//库存
	var productStock;
	//烽鸟价
	var productPrice;
	//积分赠送
    var jfzs;
    //金券赠送
     var jqzs;
	//需要金券
	var xyjq;
	//商品货号
	var productCode;
	//规格一名称
	var skuOneName;
	//规格二名称
	var skuTwoName;
	//规格一的值
	var skuOneValue;
	//规格二的值
	var skuTwoValue;

	//添加属性，，添加输入框
	$(".attr-b").click(function () {
		if($(this).attr('type')==='1'){
			var str='<div class="col-xs-4 m-tb">\n' +
					'<div class="input-group">\n' +
					'<input type="text" class="form-control i-gg i-gg-1" flag="1"/>\n' +
					'</div>\n' +
					'</div>';
			$('.div-g-1').append(str)
		}else {
			var str='<div class="col-xs-4 m-tb">\n' +
					'<div class="input-group">\n' +
					'<input type="text" class="form-control i-gg i-gg-2" flag="2"/>\n' +
					'</div>\n' +
					'</div>';
			$('.div-g-2').append(str)
		}
		//新添加属性，先解除绑定，重新绑定事件
		$(".i-gg").unbind('blur').on("blur", attrBlur);
		$(".i-gg").unbind('focus').on("focus", attrFocus);
	});

		//下拉列表改变
		$('.gg-select').change(function () {
			if(this.id==='select-1'){
				$('#th-gg-1').text($("#select-1").find("option:selected").text())
			}else {
				$('#th-gg-2').text($("#select-2").find("option:selected").text())
			}
		});

	$("#sub_btn").click(function () {
		//验证
		//商品标题
		var productName=$("#productName").val().trim();
		if (productName.length<2){
			return $.messager.alert("验证提示", "商品标题至少2个字符");
		}
		//商品图片,,一个数组
		var imgSrcArr = getImgSrc();
		if (imgSrcArr.length===0){
			return $.messager.alert("验证提示", "商品图片至少上传一张");
		}
		//商品规格
		var list=[];
		if (skuOne.length===0){
			if (skuTwo.length===0){
				//库存
				productStock=$("#show_kc").val().trim();
				//烽鸟价
				productPrice=$("#show_fnj").val().trim();
				//商品货号
				productCode=$("#show_sphh").val().trim();
				//积分赠送
                jfzs = $("#show_jfzs").val().trim();
				//代金券赠送
                jqzs=$("#show_jqzs").val().trim();
				//需要金券
				xyjq=$("#show_xyjq").val().trim();
				var tempSku={giveJf:jfzs,giveVoucher:jqzs,needJq:xyjq,fnPrice:productPrice,productStock:productStock,picture:imgSrcArr[0]};
				list.push(tempSku);
				 skuOneName=null;
				//规格二名称
				 skuTwoName=null;
				//规格一的值
				 skuOneValue=null;
				//规格二的值
				 skuTwoValue=null;
			} else {
				ggForm(list,2);
			}
		} else {
			if (skuTwo.length===0){
				ggForm(list,1)
			} else {
				ggForm(list,3)
			}
		}
		//市场价
		var marketPrice=$("#marketPrice").val();
		//结算比例
		var settleCurrency=$("#settleCurrency").val();
		//赠与比例
		var favourCurrentcy=$("#favourCurrentcy").val();

		//视频比例
		var videoType = $(':radio[name="videoType"]:checked').val();
		//视频
		var videoSrc=$("#videoInp").val();
		//文本编辑器内容
		var productDesc=UE.getEditor('editor').getContent();
		//上架区域
		var plateId="";
		$("input[name='plateId']:checked").each(function (index, item) {

			if ($("input[name='plateId']:checked").length-1===index) {
				plateId += $(this).val();
			} else {
				plateId += $(this).val() + "_";
			}
		});
		var businessId=null;
		var businessName=null;
		if (plateId===""){
			return $.messager.alert("验证提示", "请选择上架区域");
		}
		var bussTypeId=$("#b_type").val();
		if (bussTypeId==null||bussTypeId==='0'){
			return $.messager.alert("验证提示", "请选择店铺分类");
		}
		var selectedSort;

		var productTypeName;

		if (plateId!=2){
			//分类级别
			 selectedSort=$("#selectedSort").val();
			//分类名称
			 productTypeName=$("#productTypeName").val();

			if (flag==false){
				return $.messager.alert("验证提示", "请选择四级分类");
			}
		}

		//排序
		var sort=$("#sort").val().trim();
		var buyLimit=$("#buyLimit").val().trim();
		var share=$("#share").val().trim();
		var reward=$("#reward").val().trim();
		var isRecommend=0;
		if($('#isRecommend').is(':checked')) {
			isRecommend=1
		}
		var vo={productName:productName,productStock:productStock,productPrice:productPrice,productCode:productCode,businessId:businessId,businessName:businessName,bussTypeId:bussTypeId,
			skuList:list,marketPrice:marketPrice,settleCurrency:settleCurrency,favourCurrentcy:favourCurrentcy,subGraphList:JSON.stringify(imgSrcArr),
			videoType:videoType,videoSrc:videoSrc,productDesc:productDesc,plateIds:plateId,skuOneName:skuOneName,skuTwoName:skuTwoName,
			skuOne:skuOneValue,skuTwo:skuTwoValue,giveJf:jfzs,giveVoucher:jqzs,needJq:xyjq,productTypeIds:selectedSort,productTypeName:productTypeName,buyLimit:buyLimit,share:share,reward:reward,sort:sort,isRecommend:isRecommend};
		$.ajax({
			url: '/remote/product/addProduct',
			contentType:'application/json',
			type: 'post',
			data: JSON.stringify(vo),
			dataType: 'json',
			success: function (res) {
				if (res.success){
					$.messager.alert("温馨提示", "操作成功,2S之后刷新");
					setTimeout(function () {
						window.location.reload();
					}, 2000);
				}else {
					$.messager.alert("温馨提示","操作失败");
				}
			}
		});
	});

	//规格表提交的公共方法
	function ggForm(list,flag) {
		var trArr = $('#gg-tbody tr');
		var tempSku={};
		//选中的规格名字
		if (flag===1||flag===2){
			skuOneName = $("#select-"+flag).find("option:selected").text();
			skuTwoName=null;
			if (flag===1){
				skuOneValue=JSON.stringify(skuOne);
			} else {
				skuOneValue=JSON.stringify(skuTwo);
			}
			skuTwoValue=null;
			$.each(trArr,function (index,item) {
				var gg=$(item.children[0]).text().trim();
				var kc=$(item.children[1].children[0]).val().trim();
				var fnj=$(item.children[2].children[0]).val().trim();
				var jf_zs=$(item.children[3].children[0]).val().trim();
				var jq_zs=$(item.children[4].children[0]).val().trim();
				var xy_jq=$(item.children[5].children[0]).val().trim();
				var src=$(item.children[6].children[0]).val().trim();
				tempSku={skuOneName:skuOneName,skuOne:gg,productStock:kc,fnPrice:fnj,giveJf:jf_zs,giveVoucher:jq_zs,needJq:xy_jq,picture:src};
				list.push(tempSku)
			});
		} else {
			skuOneName = $("#select-1").find("option:selected").text();
			skuTwoName = $("#select-2").find("option:selected").text();
			skuOneValue=JSON.stringify(skuOne);
			skuTwoValue=JSON.stringify(skuTwo);
			$.each(trArr,function (index,item) {
				var gg1=$(item.children[0]).text().trim();
				var gg2=$(item.children[1]).text().trim();
				var kc=$(item.children[2].children[0]).val().trim();
				var fnj=$(item.children[3].children[0]).val().trim();
				var jf_zs=$(item.children[4].children[0]).val().trim();
				var jq_zs=$(item.children[5].children[0]).val().trim();
				var xy_jq=$(item.children[6].children[0]).val().trim();
				var src=$(item.children[7].children[0]).val().trim();
				tempSku={skuOneName:skuOneName,skuTwoName:skuTwoName,skuOne:gg1,skuTwo:gg2,productStock:kc,fnPrice:fnj,giveJf:jf_zs,giveVoucher:jq_zs,needJq:xy_jq,picture:src};
				list.push(tempSku)
			});
		}
		//库存
		productStock=$("#td_kc").text().trim();
		//烽鸟价
		productPrice=$("#td_fnj").text().trim();
		//商品货号
		productCode=$("#hide_sphh").val().trim();
		//积分
        jfzs=$("#td_jfzs").text().trim();
        //金券
        jqzs=$("#td_jqzs").text().trim();
		//需要金券
		xyjq=$("#td_xyjq").text().trim();
    }

	//上架区域选中事件
	$("input[name='plateId']").change(function (e) {
		if($(this).is(':checked')){
			var that=$(this);
			var plateIdArr = $("input[name='plateId']:checked");
			if (plateIdArr.length>1){
				$.each(plateIdArr,function (index,item) {
					if (item.value==="2"){
						that.attr("checked", false);
						return $.messager.alert("验证提示", "烽鸟驿站不能和其他同时选中");
					}
				});
			}else if (plateIdArr.length===1) {
				if ($(this).val()==="2"){
					$.post("/remote/BusinCates/getByAll",{},function (res) {
						if (res.success){
							$("#b_type").empty();
							var tempArr = res.data;
							if (tempArr==null||tempArr.length===0){
								$("#b_hide_div").show();
								$("#b_show_div").hide();
								return;
							}else {
								$("#b_hide_div").hide();
								$("#b_show_div").show();
							}
							var str='<option value="0">请选择商店分类</option>';
							$.each(tempArr,function (index,item) {
								str+='<option value="'+item.id+'">'+item.name+'</option>'
							});
							$("#b_type").append(str);
						}
					});
				}
			}
		}else {
			if ($(this).val()==="2"){
				$.post("/remote/BusinCate/getByBusinessId",{businessId:0},function (res) {
					if (res.success){
						$("#b_type").empty();
						var tempArr = res.data;
						if (tempArr==null||tempArr.length===0){
							$("#b_hide_div").show();
							$("#b_show_div").hide();
							return;
						}else {
							$("#b_hide_div").hide();
							$("#b_show_div").show();
						}
						var str='<option value="0">请选择商店分类</option>';
						$.each(tempArr,function (index,item) {
							str+='<option value="'+item.id+'">'+item.name+'</option>'
						});
						$("#b_type").append(str);
					}
				});
			}

		}
	});

	$(".video-button").click(function () {
		$("#videoFile").click()
	});

	$("#deleteVideo").click(function () {
		$("#videoFile").val(null);
		$("#videoInp").val(null);
		$("#videoValue").html("添加视频");
		$('#video_div').css("display","none");//不展示div
	});

	$("#videoFile").bind('input propertychange', function() {
		var file = this.files[0];
		var value = $("#videoFile").val();
		if (value!=''){
			$("#videoValue").html(value);
			var formData = new FormData();
			formData.append('file', file);
			$.ajax({
				url:'/remote/upload/video',
				type:'POST',
				data:formData,
				processData:false,
				contentType:false,
				async: true,
				success:function(res){
					if (res.code===200){
						$("#videoInp").val(res.data);
						$("#video_div").attr("src",res.data);
						$('#video_div').css("display","block");//不展示div0
					}
				}
			});
		}
	});

	//结算比例失去焦点事件
	$("#settleCurrency").blur(function () {
		var currency = $("#settleCurrency").val().trim();
		if (currency==''){
			return
		}
		if (currency<0||currency>100){
			$("#settleCurrency").val('');
			return $.messager.alert("验证提示", "请填写0-100");
		}
		var num = numSub(100,currency);
		$("#favourCurrentcy").val(num);
		if ($("#gg-tbody tr").length>0){
			var fngArr=$("#gg-tbody input.fnj");
			$.each(fngArr,function (index,item) {
				$('#gg-tbody tr:eq('+index+') input.jfzs')[0].value=Math.round(numDiv(numMulti(item.value,numDiv(num,100)),0.16));
				min(2)
			})
		}else {
			var fnj = $("#show_fnj").val().trim();
			$("#show_jfzs").val(Math.round(numDiv(numMulti(fnj,numDiv(num,100)),0.16)))
		}
	});

	//赠与比例失去焦点事件
	$("#favourCurrentcy").blur(function () {
		var currency = $("#favourCurrentcy").val().trim();
		if (currency==''){
			return
		}
		if (currency<0||currency>100){
			$("#favourCurrentcy").val('');
			return $.messager.alert("验证提示", "请填写0-100");
		}
		var num = numSub(100,currency);
		$("#settleCurrency").val(num);
		if ($("#gg-tbody tr").length>0){
			var fngArr=$("#gg-tbody input.fnj");
			$.each(fngArr,function (index,item) {
				$('#gg-tbody tr:eq('+index+') input.jfzs')[0].value=Math.round(numDiv(numMulti(item.value,numDiv(currency,100)),0.16));
				min(2)
			})
		}else {
			var fnj = $("#show_fnj").val().trim();
			$("#show_jfzs").val(Math.round(numDiv(numMulti(fnj,numDiv(currency,100)),0.16)))
		}
	})

</script>
	</body>
</html>
